<template>
  <div class="screenfull-svg" @click="click">
    <!-- <svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click" class="screenfull-svg" /> -->
    <img src="@/assets/image/scrll.png" alt="" class="wid00 hei00" />
  </div>
</template>

<script>
import screenfull from "screenfull";

export default {
  name: "Screenfull",
  data() {
    return {
      isFullscreen: false,
    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    click() {
      //建议安装下载screenfull@5版本,@5版本以上会有错误
      //该组件下载版本是@4.2.0
      /**
       * 下载
       * npm install screenfull@4.2.0
       * 引入
       * import screenfull from 'screenfull'
       * 使用
       * <svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click" class="screenfull-svg" />
       * 事件
       * if (!screenfull.enabled) {
         this.$message({
            message: 'you browser can not work',
            type: 'warning'
          })
          return false
         }
         screenfull.toggle()
       */
      console.log(JSON.stringify(screenfull.enabled));
      // if (!screenfull.enabled) {
      //   this.$message({
      //     message: "该设备不可以全屏",
      //     type: "warning",
      //   });
      //   return false;
      // }
      screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.enabled) {
        console.log(111);
        screenfull.on("change", this.change);
      }
    },
    destroy() {
      if (screenfull.enabled) {
        console.log(222);
        screenfull.off("change", this.change);
      }
    },
  },
};
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  /* background: #0D9BFF; */
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>